import pytest
from random import randint
from lly.algorithm.search.binary import Binary
@pytest.fixture(params=range(5))
def data(request):
    if request.param == 0:
        return [100] * 100
    else:
        datas = [randint(0, 1000) for i in range(10000)]
        datas.append(100)
        return sorted(datas)


def test_success(data):
    '''目标值是100'''
    search = Binary()
    result = search.search(100, data)
    print(f"result:{result}")
    assert result >= 0


def test_failure():
    '''搜索失败'''
    search = Binary()
    result = search.search(3, range(0, 100, 2))
    print(f"result:{result}")
    assert result == -1
